<?php get_header(); ?>

<div id="primary">
<?php 

$page = omeka_addons_get_parameter('addons');
$tag = omeka_addons_get_parameter('tag');

switch($page){

    case 'plugins':
        $heading = 'Plugins';
        $description = '<p>The following plugins may be downloaded separately and installed to work with <strong>Omeka 1.0</strong> and <strong>Omeka 1.1</strong>. Helpful instructions for installing plugins are on the <a href="http://omeka.org/codex/Managing_Plugins">codex</a>.  If you are looking for plugins compatible with earlier versions of Omeka, see the list of <a href="/add-ons/plugins/010-plugins/">plugins compatible with Omeka 0.10</a> and <a href="/add-ons/plugins/09-plugins/">plugins compatible with Omeka 0.9</a>.</p>';
        if($tag) {
            $addons = omeka_addons_get_addons_by_tag($tag, $page);
        } else {
            $addons = omeka_addons_get_addons('plugin');
        }
    break;
    
    case 'themes':
        $heading = 'Themes';
        if($tag) {
            $addons = omeka_addons_get_addons_by_tag($tag, $page);
        } else {
            $addons = omeka_addons_get_addons('theme', 1);
        }    break;
    
    case 'home':
        $heading = 'Add-Ons';
        $description = '<p>Add-ons extend Omeka, letting you add functionality to your Omeka website and customize its look and feel. Browse, download, and install plugins and themes to get the most from your Omeka site.</p>';
        $featuredPlugins = omeka_addons_get_featured_addons('plugin');
        $featuredThemes = omeka_addons_get_featured_addons('theme');

} 
?>
<style type="text/css" media="screen">
    .addon-info {float:left; width: 48%;}
    .versions-list {float:right; width: 48%;}
    .addon {overflow:hidden; border-bottom:1px dotted #afae99; margin-bottom:18px; padding-bottom:18px;}
    .button {
        background:#900 url("/ui/i/glass-btn.png") 0 50% repeat-x; 
        color: #fff !important; 
        text-decoration:none; 
        padding: 8px 12px;
        font-size:1.2em;
        border:1px solid #900;
        border-radius: 8px;
        -moz-border-radius: 8px;
        -webkit-border-radius: 8px;
        text-align:center;
        }
    .button:hover {background-color: #b00; border-color: #b00;}
    .theme-thumbnail {width: 300px;margin-bottom:18px;}
    .theme-thumbnail img {max-width: 100%;display:block;}
</style>
<h1><?php echo $heading; if($tag) echo ' tagged &#8220;'.$tag.'&#8221;';?></h1>

<?php echo $description; ?>
<?php
if($page == 'home'): ?>

<div id="featured-plugins" class="featured-addons">
    <h2>Featured Plugins</h2>
    
<?php foreach($featuredPlugins as $plugin): ?>
<h3><a href="<?php echo omeka_addons_get_anchor($plugin) ?>"><?php echo $plugin->addon_name; ?></a></h3>
<p><?php echo $plugin->addon_description; ?></p>
<?php $latestVersion = omeka_addons_get_latest_addon_version($plugin->id); ?>
<?php endforeach; ?>
<p class="featured-nav"><a id="download-plugins" href="<?php echo omeka_addons_get_browse_link('plugins'); ?>">Browse Plugins</a> <a href="/get-involved/develop/">Build a Plugin</a></p>
</div>

<div id="featured-theme" class="featured-addons">
<h2>Featured Theme</h2>
<?php foreach($featuredThemes as $theme): ?>
<h3><a href="<?php echo omeka_addons_get_anchor($theme) ?>"><?php echo $theme->addon_name; ?></a></h3>
<?php $latestVersion = omeka_addons_get_latest_addon_version($theme->id); ?>
<a href="<?php echo omeka_addons_get_anchor($theme) ?>">
<img src="https://addons.omeka.org/svn/themes/<?php echo $theme->directory_name ?>/tags/<?php echo $latestVersion->tag_directory ?>/theme.jpg" />
</a>
<p><?php echo $theme->addon_description; ?></p>
<?php endforeach; ?>
<p class="featured-nav"><a href="<?php echo omeka_addons_get_browse_link('themes'); ?>">Browse Themes</a> <a href="/get-involved/design/">Design a Theme</a></p>
</div>

<?php else: ?>
<?php if(!empty($addons)): ?>

<?php foreach($addons as $addon):
    $versions = omeka_addons_get_versions($addon->id);
    $latestVersion = $versions[0];
    
    $addonName = !empty($addon->addon_name) ? $addon->addon_name : $addon->directory_name;
    $addonDescription = !empty($addon->addon_description) ? $addon->addon_description : $latestVersion->description;
  
?>
    <?php if($page == 'plugins'): ?>
        <div id="<?php echo strtolower($addon->directory_name); ?>" class="plugin addon">
            <h2><?php echo $addonName; ?></h2>
            
            <?php

            
            ?>
            <div class="addon-info">
                <?php echo omeka_addons_display_tags_for_addon($addon); ?>
                
            <p><?php echo $addonDescription; ?><?php if($link = $latestVersion->link) echo ' <a href="'.$link.'">Instructions</a>'; ?></p>
            <p class="latest-release"><a href="<?php echo omeka_addons_get_download($latestVersion); ?>" class="button">Latest Release: <?php echo $latestVersion->tag_directory; ?></a></p>
            </div>
            <?php if($versions): ?>
                
            <div class="versions-list">
                <h3>All Versions</h3>
                
                <table width="100%">
                    <thead>
                        <tr>
                            <th>Available Versions</th>
                            <th>Minimum Omeka Version</th>
                            <th>Download</th>
                        </tr>
                    </thead>
                    <tbody>
                <?php foreach($versions as $version): ?>
                    <tr>
                        <th scope="row"><?php echo $version->tag_directory; ?></th>
                        <td><?php echo $version->omeka_minimum_version; ?></td>
                        <td><a href="<?php echo omeka_addons_get_download($version); ?>">Download</a></td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
                </table>
            </div>
            <?php endif; ?>
        </div>
        <?php elseif($page == 'themes'): ?>
            <div id="<?php echo strtolower($addon->directory_name); ?>" class="theme addon">
                <h2><?php echo $addonName; ?></h2>
                <div class="addon-info">
                    <?php echo omeka_addons_display_tags_for_addon($addon); ?>
                    
                <p><?php echo $addonDescription; ?></p>
                <div class="theme-thumbnail">
                <img src="https://addons.omeka.org/svn/themes/<?php echo $addon->directory_name ?>/tags/<?php echo $versions[0]->tag_directory ?>/theme.jpg" />
                </div>
<p class="latest-release"><a href="<?php echo omeka_addons_get_download($latestVersion); ?>" class="button">Latest Release: <?php echo $latestVersion->tag_directory; ?></a></p>                
</div>
                <?php if($versions): ?>
                    <div class="versions-list">
                    <h3>All Versions</h3>
                    <table width="100%">
                        <thead>
                            <tr>
                                <th>Available Versions</th>
                                <th>Minimum Omeka Version</th>
                                <th>Download</th>
                            </tr>
                        </thead>
                        <tbody>
                    <?php foreach($versions as $version): ?>
                        <tr>
                            <th scope="row"><?php echo $version->tag_directory; ?></th>
                            <td><?php echo $version->omeka_minimum_version; ?></td>
                            <td><a href="<?php echo omeka_addons_get_download($version); ?>">Download</a></td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                    </table>
                    </div>
                <?php endif; ?>
            </div>
        <?php endif; ?>
    <?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
</div>
<?php get_footer(); ?>